package com.af.monitorModule.controller.live;

import com.af.monitorModule.common.ResultEnum;
import com.af.monitorModule.generator.entity.Monitor;
import com.af.monitorModule.generator.mapper.MonitorMapper;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/heart")
public class Heartbeat {

    @Autowired
    private MonitorMapper monitorMapper;

    @GetMapping("/jump/{monitorId}")
    public JSONObject jump(@PathVariable("monitorId") String monitorId){
        Monitor monitor = new Monitor();
        monitor.setId(Integer.parseInt(monitorId));
        monitor.setHeartbeat(LocalDateTime.now());
        if(monitorMapper.updateById(monitor) == 1){
            return ResultEnum.OK.getResult();
        }else {
            return ResultEnum.HEART_ERROR.getResult();
        }
    }
}
